﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HZ.Supervise.Model;

public partial class login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {


    }
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string userId = txtUserId.Text.Trim();
        string pwd = txtUserPwd.Text.Trim();
        string code = this.txtCode.Text;
        HZ.Supervise.IBLL.IBLL_Login iu = HZ.Supervise.BLLFactory.BLL_Login();
        if (CurrentAccount.VerifyValidateCode(code))
        {
            User user = new User();
            int result = iu.Login(userId, pwd, out user);
            if (result == 1 && user.UserRole != null)
            {
                if (user.UserRole.RoleID == "04") //监管角色限制  user.UserRole.RoleID == "03" || (user.UserRole.RoleID == "01" && user.Org.SNKEY == "1") || 
                {
                    //获取用户信息,存入session中                   
                    CurrentAccount.SetUser(user);

                    //添加登录日志
                    LoginLog ll = new LoginLog();
                    ll.ID = Guid.NewGuid().ToString();
                    ll.UID = user.UserID;
                    ll.UName = user.UserName;
                    ll.OID = user.Org.OrgID;
                    ll.WW = hfip.Value;
                    ll.LeiBie = "试剂监管";
                    ll.OpTime = DateTime.Now;
                    iu.AddLoginLog(ll);

                    //普通跳转方式
                    string str = "parent.location='PageControl/Center2.aspx'";
                    Response.Write(HZ.Web.WebUtil.GetScript(str));
                } 
                else {
                    HZ.Web.WebUtil.Alert("此用户没有监管权限！", this);
                    this.txtCode.Text = "";
                }

            }
            else
            {
                HZ.Web.WebUtil.Alert("用户名密码不匹配！", this);
                this.txtCode.Text = "";
            }
        }
        else
        {
            this.txtCode.Text = "";
            HZ.Web.WebUtil.Alert("验证码不正确！", this);
        }
    }

    protected void txtreset_Click(object sender, EventArgs e)
    {
        txtUserId.Text = "";
        txtUserPwd.Text = "";
    }
}
